package com.bilu.common.component;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.web.servlet.config.annotation.CorsRegistration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 跨域设置
 */
@Configuration
public class CorsConfigurer implements WebMvcConfigurer{
	@Override
	public void addCorsMappings(CorsRegistry registry) {
		//添加映射路径
		CorsRegistration corsRegistration = registry.addMapping("/**");
		//是否允许Cookie
		corsRegistration.allowCredentials(true);
		//允许访问的原始域
		corsRegistration.allowedOriginPatterns("*");
		//允许的请求方式
		corsRegistration.allowedMethods(new String[] {HttpMethod.GET.name(),HttpMethod.POST.name()});
		//允许的请求头部信息
		corsRegistration.allowedHeaders("*");
		corsRegistration.maxAge(3600);
		//允许返回的头部信息
		corsRegistration.exposedHeaders("*");
	}
}
